//
//  NSString+MobileNo.m
//  YYZB
//
//  Created by 顾悦 on 16/3/28.
//
//

#import "NSString+MobileNo.h"

@implementation NSString (MobileNo)

- (BOOL)isMobileNumber {
    
    NSString *MOBILE = @"^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
    NSString *CM = @"^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
    NSString *CU = @"^1(3[0-2]|5[256]|8[56])\\d{8}$";
    NSString *CT = @"^1((33|53|8[09])[0-9]|349)\\d{7}$";
    NSString *OT = @"^1\\d{10}$";
    
    NSPredicate *regextestmobile = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", MOBILE];
    NSPredicate *regextestcm = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CM];
    NSPredicate *regextestcu = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CU];
    NSPredicate *regextestct = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", CT];
    NSPredicate *regextestot = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", OT];
    
    if ([regextestmobile evaluateWithObject:self]
        || [regextestcm evaluateWithObject:self]
        || [regextestcu evaluateWithObject:self]
        || [regextestct evaluateWithObject:self]
        || [regextestot evaluateWithObject:self]) {
        return YES;
    } else {
        return NO;
    }
}

@end
